<?php

/**
* Store template in session to raise it after self redirect.
* 
*/
class Kernel_Form_Template 
{
    
    /**
    * Session var name
    */
    const SESSION_VAR = 'FORM_TEMPLATE_SAVED';
    
    /**
    * Template name.
    * 
    * @var string
    */
    private $_template;
    
    /**
    * Set template
    * 
    * @param string $template
    */
    public function __construct($template) 
    {
        $this->_template = $template;
    }
    
    /**
    * Store object in session
    * 
    */
    public function store() 
    {
        $_SESSION[self::SESSION_VAR] = $this;
    }
    
    /**
    * Get template name from session
    * 
    */
    static public function get() 
    {
        $var = self::SESSION_VAR;
        $template = isset($_SESSION[$var]) && $_SESSION[$var] instanceof self
            ? $_SESSION[$var]->_template : null;
        unset($_SESSION[$var]);
        return $template;
    }
    
}